package com.mapgoo.scalike

import scalikejdbc._
import scalikejdbc.config._

/**
  *
  * @author eureka.wh
  * @since 2019-05-30 17:37
  */

case class Girl(id: Int, age: Int, cup_size: String)
object Scalike01 {

  def main(args: Array[String]): Unit = {

        test02()
  }

   def test02()={

     DBs.setup('hadoop)
//     DBs.loadGlobalSettings()
//
     NamedDB('hadoop) localTx{
       implicit session =>
         sql"insert into people(age,name) values(60,'xxoo')".update().apply()
         SQL("update people set age = 999 where name = 'twh'").update().apply()
     }

     DBs.closeAll()
   }


   def test01(): Unit ={

     // 默认使用配置文件里面的db.default下面的库
     // DBs.setupAll()

     // 使用hadoop的库
     DBs.setup('hadoop)

     val result = NamedDB('hadoop) readOnly{ implicit session =>
       sql"select * from emp"
         .map(rs=>(rs.int("id"),rs.string("emp_name"))).list().apply()
     }

     //  val result = NamedDB('test) readOnly{ implicit session =>
     //    sql"select * from girl"
     //      .map(rs=>Girl(rs.int("id"),
     //        rs.int("age"),
     //        rs.string("cup_size"))).list().apply()
     //  }

     println(result)

     DBs.closeAll()

   }
}








